from data import *
import numpy as np
from scipy import interpolate
import pylab as pl
import pandas as pd



x=np.array(si_n)[:,0].tolist()[0:226]
#x=[  0.   1.   2.   3.   4.   5.   6.   7.   8.   9.  10.]
y=np.array(si_n)[:,1].tolist()[0:226]
# xnew=np.linspace(190.7,805.1,308)
xnew=np.linspace(190.7,805.1,308)
pl.plot(x,y,"ro")


list1=["slinear","quadratic","cubic"]
list2=["线性-结果","抛物线-结果","样条插值-结果"]


for index,kind in enumerate(list1):#插值方式
    f=interpolate.interp1d(x,y,kind=kind)
    ynew=f(xnew)#f是插值计算
    pl.plot(xnew,ynew,label=str(kind))
    print("插值方法:",list2[index])


    print("写入文件:\n",list2[index]+".csv")
    data=[xnew,ynew]
    df_data=pd.DataFrame([],columns=['wavelength','n'])
    df_data['wavelength']=data[0]
    df_data['n']=data[1]
    df_data.to_csv("Si-"+list2[index]+".csv",index=False)


# 可视化
pl.legend(loc="lower right")
pl.show()